//
//  ViewController.m
//  01-瀑布流
//
//  Created by 紫荆秋雪 on 16/3/6.
//  Copyright © 2016年 紫荆秋雪. All rights reserved.
//

#import "ViewController.h"
#import "WRWaterLayout.h"

static NSString * const ID = @"cell";

@interface ViewController ()<UICollectionViewDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //创建collectionView
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:[[WRWaterLayout alloc] init]];
    
    //设置背景颜色
    collectionView.backgroundColor = [UIColor whiteColor];
    
    //设置代理
    collectionView.dataSource = self;
    
    //添加到view中
    [self.view addSubview:collectionView];
    
    //注册cell
    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:ID];
    
}

#pragma mark -UICollectionViewDataSource方法的实现
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 50;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor orangeColor];
    
    NSInteger tag = 10;
    UILabel *label = (UILabel *)[cell.contentView viewWithTag:tag];
    if (label == nil) {
        label = [[UILabel alloc] init];
        label.tag = tag;
        [cell.contentView addSubview:label];
    }
    
    label.text = [NSString stringWithFormat:@"%zd", indexPath.item];
    [label sizeToFit];
    
    return cell;
}
@end
